<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
    <form>
        商品名称：<input type="text" v-model="product.productName"><br>
        商品价格：<input type="text" v-model="product.price"><br>
        上架时间：<input type="date" v-model="product.createTime"><br>

    </form>
    <button v-on:click="sub">提交</button>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            product: {
                id:""
            }
        },
        methods: {

            sub: function (res) {
                axios.post("/product/updateOrSave", this.product).then(function (res) {
                    window.location.href = "index.html";
                })
            },

            findById: function (id) {
                var _this = this;
                axios.get("/product/findById?id=" + id).then(function (res) {
                    _this.product = res.data;
                })
            }
        },
        mounted() {
         var id=  window.localStorage.getItem("id");
         if (id!=null){
             this.findById(id);
         }
        }

    })
</script>
</html>